package com.jk.smartelderlycare.controller;

import com.jk.smartelderlycare.dto.SysPharm;
import com.jk.smartelderlycare.dto.SysRole;
import com.jk.smartelderlycare.pojo.PagedResponse;
import com.jk.smartelderlycare.pojo.ResponseResult;
import com.jk.smartelderlycare.security.LoginUser;
import com.jk.smartelderlycare.service.SysPharmServiceFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author hhk
 * @version 1.0
 * @ClassName SysPharmController
 * @program: smart-elderly-care
 * @description: TODO
 * @date 2024/11/7 19:03
 */
@Api(tags = "药品管理模块")
@RestController
@CrossOrigin
@RequestMapping(value = "sysPharm")
public class SysPharmController {
    @Autowired
    private SysPharmServiceFeign sysPharmServiceFeign;
    /**
     * @description: 药品后端分页查询
     * @param: [sysPharm, pageNum, pageSize]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult<com.jk.smartelderlycare.pojo.PagedResponse<com.jk.smartelderlycare.dto.SysPharm>>
     * @author hhk
     * @date: 2024/11/7 19:14
     */
    @ApiOperation(value = "药品后端分页查询",httpMethod = "POST",notes = "药品后端分页查询")
    @PostMapping(value = "findSysPharmPaginationList")
    public ResponseResult<PagedResponse<SysPharm>>findSysPharmPaginationList(@RequestBody SysPharm sysPharm, @RequestParam(value = "pageNum") Integer pageNum, @RequestParam(value = "pageSize") Integer pageSize) {
        return new ResponseResult<>(200,"查询成功",sysPharmServiceFeign.findSysPharmPaginationList(sysPharm, pageNum, pageSize));
    }
    /**
     * @description: 新增药品列表
     * @param: [sysPharm]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult
     * @author hhk
     * @date: 2024/11/7 19:16
     */
    @ApiOperation(value = "新增药品列表",httpMethod = "POST",notes = "新增药品列表")
    @PostMapping(value = "addSysPharm")
    public ResponseResult addSysPharm(@RequestBody SysPharm sysPharm) {
        try {
            sysPharmServiceFeign.addSysPharm(sysPharm);
            return new ResponseResult(200,"新增成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(500,"新增失败");
        }
    }
    /**
     * @description: 根据id删除一条数据
     * @param: [pharmId]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult
     * @author hhk
     * @date: 2024/11/7 19:20
     */
    @ApiOperation(value = "根据id删除一条数据",httpMethod = "DELETE",notes = "根据id删除一条数据")
    @DeleteMapping(value = "deleteSysPharmByPharmId")
    private ResponseResult deleteSysPharmByPharmId(@RequestParam(value = "pharmId") Long pharmId) {
        try {
            sysPharmServiceFeign.deleteSysPharmByPharmId(pharmId);
            return new ResponseResult(200,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(500,"删除失败");
        }
    }
    /**
     * @description: 根据id回显一条数据
     * @param: [pharmId]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult<com.jk.smartelderlycare.dto.SysPharm>
     * @author hhk
     * @date: 2024/11/7 19:26
     */
    @ApiOperation(value = "根据id回显一条数据",httpMethod = "GET",notes = "根据id回显一条数据")
    @GetMapping(value = "findSysPharmByPharmId")
    private ResponseResult<SysPharm>findSysPharmByPharmId(@RequestParam(value = "pharmId") Long pharmId) {
        return new ResponseResult<>(200,"回显成功",sysPharmServiceFeign.findSysPharmByPharmId(pharmId));
    }
    /**
     * @description: 修改药品列表
     * @param: [sysPharm]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult
     * @author hhk
     * @date: 2024/11/7 19:27
     */
    @ApiOperation(value = "修改药品列表",httpMethod = "PUT",notes = "修改药品列表")
    @PutMapping(value = "updateSysPharm")
    private ResponseResult updateSysPharm(@RequestBody SysPharm sysPharm) {
        try {
            //获取当前登陆人赋修改时间与修改人
            LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
            sysPharm.setModifyDate(new Date());
            sysPharm.setModifyUser(loginUser.getUser().getUserName());
            sysPharmServiceFeign.updateSysPharm(sysPharm);
            return new ResponseResult(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(500,"修改失败");
        }
    }
    /**
     * @description: 状态修改
     * @param: [sysPharm]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult
     * @author hhk
     * @date: 2024/11/7 19:30
     */
    @ApiOperation(value = "状态修改",httpMethod = "PUT",notes = "状态修改")
    @PutMapping(value = "updateStatusById")
    private ResponseResult updateStatusById(@RequestBody SysPharm sysPharm) {
        try {
            sysPharmServiceFeign.updateStatusById(sysPharm);
            return new ResponseResult(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(500,"修改失败");
        }
    }






}
